package com.health.system.action.system;

import static com.health.system.javacommon.util.Struts2JsonHelper.outString;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.security.access.prepost.PreAuthorize;

import com.health.system.javacommon.base.BaseStruts2Action;
import com.health.system.javacommon.util.JsonUtil;
import com.health.system.springSecurity.LogonUser;
import com.health.system.service.system.UserManager;
import com.health.system.springSecurity.UserInfo;

/**
 * <p>Title:读取保存在用户信息中的菜单信息</p> 
 * Description: 页面通过Ajax调用Action层,返回JSONO数据
 * Copyright: Copyright (c) 2011-03 
 * Company: 
 * @author 
 * @version 2.0 
*/

public class MenuAction extends BaseStruts2Action {

	private UserManager userManager;

	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}

	/**
	 * 读取保存在用户信息中的菜单信息 
	 * 登录成功刷新菜单同时写入用户IP地址信息
	 * 刘文辉 2011-03-22
	 * @throws IOException
	 */
 
	public void list() throws IOException {
		// 设置已经登录
		ServletActionContext.getRequest().getSession().setAttribute("isLogin","true");
		UserInfo userInfo = LogonUser.logonUser();
		if (userInfo != null) {
			HttpServletRequest request = ServletActionContext.getRequest();
			String ip = (String) request.getRemoteAddr();
			userInfo.setIp(ip);
			String userName = userInfo.getUsername();
			if (null != userName && !"".equals(userName)) {
				userManager.updateLogincountByUserName(userName);
			}
			String menus = userInfo.getUserMenuInfo();
			outString(menus);
		}
	}

}
